//
//  HBChannelRequest.m
//  HeartBeat
//
//  Created by karong on 2023/8/29.
//

#import "HBChannelRequest.h"
#import "HBCategoryModel.h"
@implementation HBChannelRequest
- (NSDictionary *)categoryDic {
    NSDictionary * dic = @{@"channel_type":@(self.category.channelType),
                           @"category_id":@(self.category.category.id),
                           @"finish_type":@(self.category.finish_type.id),
                           @"pay_type":@(self.category.pay_type.id),
                           @"word_type":@(self.category.word_type.id),
                           @"sort_type":@(self.sort_type)
    };
    return dic;
}

- (void)refreshDataSuccess:(回调一个数组)success failed:(失败回调)failed {
    if (self.loading) {
        return;
    }
    self.loading = YES;
    self.haveMore = YES;
    self.page = 1;
    [HBRequest loadCategoryListWithCategoryDic:[self categoryDic] page:self.page success:^(NSArray *array) {
        [self loadSuccess:success withArray:array];
    } failed:^(NSURLResponse * _Nonnull response, NSError * _Nonnull error, id  _Nonnull responseObject) {
        failed(response, error, responseObject);
        self.loading = NO;
    }];
}


- (void)loadMoreDataSuccess:(回调一个数组)success failed:(失败回调)failed {
    if (self.loading && !self.haveMore) {
        return;
    }
    [HBRequest loadCategoryListWithCategoryDic:[self categoryDic] page:self.page success:^(NSArray *array) {
        [self loadSuccess:success withArray:array];
    } failed:^(NSURLResponse * _Nonnull response, NSError * _Nonnull error, id  _Nonnull responseObject) {
        failed(response, error, responseObject);
        self.loading = NO;
    }];
}
@end
